﻿'
' DKP for DotNetNuke® - http://dkpdnn.codeplex.com
' Copyright (c) 2008
' by Casey Lengacher ( http://dkpdnn.codeplex.com )
'
' DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
' SOFTWARE.
'

Imports System
Imports System.Data
Imports System.Configuration
Imports Microsoft.ApplicationBlocks.Data
Imports System.Data.SqlClient
Imports DotNetNuke.Framework.Providers

Namespace DotNetNuke.Modules.tss_DKP

    Public Class SqlDataProvider
        Inherits tss_DataProvider

#Region "Private Members"

        Private Const ProviderType As String = "data"

        Private _providerConfiguration As ProviderConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType)
        Private _connectionString As String
        Private _providerPath As String
        Private _objectQualifier As String
        Private _databaseOwner As String

#End Region

#Region "Constructors"

        Public Sub New()

            ' Read the configuration specific information for this provider
            Dim objProvider As Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Provider)

            ' Read the attributes for this provider
            If objProvider.Attributes("connectionStringName") <> "" AndAlso _
            ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName")) <> "" Then
                _connectionString = ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName"))
            Else
                _connectionString = objProvider.Attributes("connectionString")
            End If

            _providerPath = objProvider.Attributes("providerPath")

            _objectQualifier = objProvider.Attributes("objectQualifier")
            If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
                _objectQualifier += "_"
            End If

            _databaseOwner = objProvider.Attributes("databaseOwner")
            If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
                _databaseOwner += "."
            End If

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property ConnectionString() As String
            Get
                Return _connectionString
            End Get
        End Property

        Public ReadOnly Property ProviderPath() As String
            Get
                Return _providerPath
            End Get
        End Property

        Public ReadOnly Property ObjectQualifier() As String
            Get
                Return _objectQualifier
            End Get
        End Property

        Public ReadOnly Property DatabaseOwner() As String
            Get
                Return _databaseOwner
            End Get
        End Property

#End Region

#Region "Board Methods"
        Public Overrides Function tss_GetBoard(ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetBoard", BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetBoards(ByVal PortalID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetBoards", PortalID), IDataReader)
        End Function
        Public Overrides Function tss_GetBoardsByPage(ByVal PortalID As Integer, _
                                                      ByVal PageNumber As Integer, _
                                                      ByVal PageSize As Integer, _
                                                      ByVal SortExpression As String, _
                                                      ByVal SortDirection As String, _
                                                      ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetBoardsByPage", _
                                                                  PortalID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteBoard(ByVal BoardID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteBoard", BoardID)
        End Sub
        Public Overrides Function tss_AddBoard(ByVal BoardName As String, _
                                               ByVal GameID As Integer, _
                                               ByVal SystemID As Integer, _
                                               ByVal GuildName As String, _
                                               ByVal RegionName As String, _
                                               ByVal RealmName As String, _
                                               ByVal GoodAttendanceCutOff As Integer, _
                                               ByVal BadAttendanceCutOff As Integer, _
                                               ByVal PlayerSyncCutOff As Integer, _
                                               ByVal PortalID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddBoard", _
                                                     BoardName, _
                                                     GameID, _
                                                     SystemID, _
                                                     GuildName, _
                                                     RegionName, _
                                                     RealmName, _
                                                     GoodAttendanceCutOff, _
                                                     BadAttendanceCutOff, _
                                                     PlayerSyncCutOff, _
                                                     PortalID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateBoard(ByVal BoardID As Integer, _
                                             ByVal BoardName As String, _
                                             ByVal GameID As Integer, _
                                             ByVal SystemID As Integer, _
                                             ByVal GuildName As String, _
                                             ByVal RegionName As String, _
                                             ByVal RealmName As String, _
                                             ByVal GoodAttendanceCutOff As Integer, _
                                             ByVal BadAttendanceCutOff As Integer, _
                                             ByVal PlayerSyncCutOff As Integer, _
                                             ByVal PortalID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateBoard", _
                                          BoardID, _
                                          BoardName, _
                                          GameID, _
                                          SystemID, _
                                          GuildName, _
                                          RegionName, _
                                          RealmName, _
                                          GoodAttendanceCutOff, _
                                          BadAttendanceCutOff, _
                                          PlayerSyncCutOff, _
                                          PortalID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Class Methods"
        Public Overrides Function tss_GetClasses(ByVal GameID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetClasses", GameID), IDataReader)
        End Function
#End Region

#Region "Drop Methods"
        Public Overrides Function tss_GetDrop(ByVal DropID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetDrop", DropID), IDataReader)
        End Function
        Public Overrides Function tss_GetDropByMobIDItemID(ByVal MobId As Integer, _
                                                           ByVal ItemId As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetDropByMobIDItemID", _
                                                 MobId, _
                                                 ItemId), IDataReader)
        End Function
        Public Overrides Function tss_GetDrops(ByVal RaidID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetDrops", RaidID), IDataReader)
        End Function
        Public Overrides Function tss_GetDropsByPage(ByVal MobID As Integer, _
                                                           ByVal PageNumber As Integer, _
                                                           ByVal PageSize As Integer, _
                                                           ByVal SortExpression As String, _
                                                           ByVal SortDirection As String, _
                                                           ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetDropsByPage", _
                                                                  MobID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteDrop(ByVal DropID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteDrop", DropID)
        End Sub
        Public Overrides Function tss_AddDrop(ByVal MobID As Integer, _
                                              ByVal ItemID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddDrop", _
                                                     MobID, _
                                                     ItemID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateDrop(ByVal DropID As Integer, _
                                            ByVal MobID As Integer, _
                                            ByVal ItemID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateDrop", _
                                          DropID, _
                                          MobID, _
                                          ItemID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Game Methods"
        Public Overrides Function tss_GetGames() As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetGames"), IDataReader)
        End Function
#End Region

#Region "Instance Methods"
        Public Overrides Function tss_GetInstance(ByVal InstanceID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetInstance", InstanceID), IDataReader)
        End Function
        Public Overrides Function tss_GetInstanceByName(ByVal InstanceName As String, _
                                                        ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetInstanceByName", _
                                                 InstanceName, _
                                                 BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetInstances(ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetInstances", BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetInstancesByPage(ByVal BoardID As Integer, _
                                                         ByVal PageNumber As Integer, _
                                                         ByVal PageSize As Integer, _
                                                         ByVal SortExpression As String, _
                                                         ByVal SortDirection As String, _
                                                         ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetInstancesByPage", _
                                                                  BoardID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteInstance(ByVal InstanceID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteInstance", InstanceID)
        End Sub
        Public Overrides Function tss_AddInstance(ByVal InstanceName As String, _
                                                  ByVal InstanceWowHeadID As String, _
                                                  ByVal InstanceHeroicFlag As Boolean, _
                                                  ByVal BoardID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddInstance", _
                                                     InstanceName, _
                                                     InstanceWowHeadID, _
                                                     InstanceHeroicFlag, _
                                                     BoardID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateInstance(ByVal InstanceID As Integer, _
                                                ByVal InstanceName As String, _
                                                ByVal InstanceWowHeadID As String, _
                                                ByVal InstanceHeroicFlag As Boolean)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateInstance", _
                                          InstanceID, _
                                          InstanceName, _
                                          InstanceWowHeadID, _
                                          InstanceHeroicFlag)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Item Methods"
        Public Overrides Function tss_GetItem(ByVal ItemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetItem", ItemID), IDataReader)
        End Function
        Public Overrides Function tss_GetItemByName(ByVal ItemName As String, _
                                                    ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetItemByName", _
                                                 ItemName, _
                                                 BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetItems(ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetItems", BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetItemsByPage(ByVal BoardID As Integer, _
                                                     ByVal PageNumber As Integer, _
                                                     ByVal PageSize As Integer, _
                                                     ByVal SortExpression As String, _
                                                     ByVal SortDirection As String, _
                                                     ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetItemsByPage", _
                                                                  BoardID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteItem(ByVal ItemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteItem", ItemID)
        End Sub
        Public Overrides Function tss_AddItem(ByVal ItemName As String, _
                                              ByVal ItemValue As Double, _
                                              ByVal ItemPercent As Integer, _
                                              ByVal ItemWowHeadID As String, _
                                              ByVal BoardID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddItem", _
                                                     ItemName, _
                                                     ItemValue, _
                                                     ItemPercent, _
                                                     ItemWowHeadID, _
                                                     BoardID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateItem(ByVal ItemID As Integer, _
                                            ByVal ItemName As String, _
                                            ByVal ItemValue As Double, _
                                            ByVal ItemPercent As Integer, _
                                            ByVal ItemWowHeadID As String)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateItem", _
                                          ItemID, _
                                          ItemName, _
                                          ItemValue, _
                                          ItemPercent, _
                                          ItemWowHeadID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Level Methods"
        Public Overrides Function tss_GetLevels(ByVal GameID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetLevels", GameID), IDataReader)
        End Function
#End Region

#Region "Loot Methods"
        Public Overrides Function tss_GetLoot(ByVal LootID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetLoot", LootID), IDataReader)
        End Function
        Public Overrides Function tss_GetLootsByPage(ByVal RaidID As Integer, _
                                                            ByVal PageNumber As Integer, _
                                                            ByVal PageSize As Integer, _
                                                            ByVal SortExpression As String, _
                                                            ByVal SortDirection As String, _
                                                            ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetLootsByPage", _
                                                                  RaidID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Function tss_GetLootsForPlayerByPage(ByVal PlayerID As Integer, _
                                                              ByVal PageNumber As Integer, _
                                                              ByVal PageSize As Integer, _
                                                              ByVal SortExpression As String, _
                                                              ByVal SortDirection As String, _
                                                              ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetLootsForPlayerByPage", _
                                                                  PlayerID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteLoot(ByVal LootID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteLoot", LootID)
        End Sub
        Public Overrides Function tss_AddLoot(ByVal LootValue As Double, _
                                              ByVal RaidID As Integer, _
                                              ByVal PlayerID As Integer, _
                                              ByVal DropID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddLoot", _
                                                     LootValue, _
                                                     RaidID, _
                                                     PlayerID, _
                                                     DropID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateLoot(ByVal LootID As Integer, _
                                            ByVal LootValue As Double, _
                                            ByVal RaidID As Integer, _
                                            ByVal PlayerID As Integer, _
                                            ByVal DropID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateLoot", _
                                          LootID, _
                                          LootValue, _
                                          RaidID, _
                                          PlayerID, _
                                          DropID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Mob Methods"
        Public Overrides Function tss_GetMob(ByVal MobID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetMob", MobID), IDataReader)
        End Function
        Public Overrides Function tss_GetMobByName(ByVal MobName As String, _
                                                   ByVal InstanceID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetMobByName", _
                                                 MobName, _
                                                 InstanceID), IDataReader)
        End Function
        Public Overrides Function tss_GetMobs(ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetMobs", BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetMobsByPage(ByVal BoardID As Integer, _
                                                    ByVal PageNumber As Integer, _
                                                    ByVal PageSize As Integer, _
                                                    ByVal SortExpression As String, _
                                                    ByVal SortDirection As String, _
                                                    ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetMobsByPage", _
                                                                  BoardID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteMob(ByVal MobID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteMob", MobID)
        End Sub
        Public Overrides Function tss_AddMob(ByVal MobName As String, _
                                             ByVal MobValue As Double, _
                                             ByVal MobWowHeadID As String, _
                                             ByVal MobHeroicFlag As Boolean, _
                                             ByVal MobAttendanceFlag As Boolean, _
                                             ByVal InstanceID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddMob", _
                                                     MobName, _
                                                     MobValue, _
                                                     MobWowHeadID, _
                                                     MobHeroicFlag, _
                                                     MobAttendanceFlag, _
                                                     InstanceID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateMob(ByVal MobID As Integer, _
                                           ByVal MobName As String, _
                                           ByVal MobValue As Double, _
                                           ByVal MobWowHeadID As String, _
                                           ByVal MobHeroicFlag As Boolean, _
                                           ByVal MobAttendanceFlag As Boolean, _
                                           ByVal InstanceID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateMob", _
                                          MobID, _
                                          MobName, _
                                          MobValue, _
                                          MobWowHeadID, _
                                          MobHeroicFlag, _
                                          MobAttendanceFlag, _
                                          InstanceID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Player Methods"
        Public Overrides Function tss_GetPlayer(ByVal PlayerID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayer", PlayerID), IDataReader)
        End Function
        Public Overrides Function tss_GetPlayerByName(ByVal PlayerName As String, _
                                                      ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayerByName", _
                                                 PlayerName, _
                                                 BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetPlayers(ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayers", BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetPlayersByClass(ByVal PlayerClass As String, _
                                                        ByVal BoardID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayersByClass", _
                                                 PlayerClass, _
                                                 BoardID), IDataReader)
        End Function
        Public Overrides Function tss_GetPlayersByRaid(ByVal RaidID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayersByRaid", RaidID), IDataReader)
        End Function
        Public Overrides Function tss_GetPlayersByPage(ByVal BoardID As Integer, _
                                                       ByVal PageNumber As Integer, _
                                                       ByVal PageSize As Integer, _
                                                       ByVal SortExpression As String, _
                                                       ByVal SortDirection As String, _
                                                       ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetPlayersByPage", _
                                                                  BoardID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeletePlayer(ByVal PlayerID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeletePlayer", PlayerID)
        End Sub
        Public Overrides Function tss_AddPlayer(ByVal PlayerName As String, _
                                                ByVal PlayerRank As String, _
                                                ByVal PlayerClass As String, _
                                                ByVal PlayerRace As String, _
                                                ByVal PlayerLevel As String, _
                                                ByVal JoinDate As DateTime, _
                                                ByVal BoardID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddPlayer", _
                                                     PlayerName, _
                                                     PlayerRank, _
                                                     PlayerClass, _
                                                     PlayerRace, _
                                                     PlayerLevel, _
                                                     JoinDate, _
                                                     BoardID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdatePlayer(ByVal PlayerID As Integer, _
                                              ByVal PlayerName As String, _
                                              ByVal PlayerRank As String, _
                                              ByVal PlayerClass As String, _
                                              ByVal PlayerRace As String, _
                                              ByVal PlayerLevel As String, _
                                              ByVal JoinDate As DateTime)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdatePlayer", _
                                          PlayerID, _
                                          PlayerName, _
                                          PlayerRank, _
                                          PlayerClass, _
                                          PlayerRace, _
                                          PlayerLevel, _
                                          JoinDate)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Race Methods"
        Public Overrides Function tss_GetRaces(ByVal GameID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRaces", GameID), IDataReader)
        End Function
#End Region

#Region "Raid Methods"
        Public Overrides Function tss_GetRaid(ByVal RaidID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRaid", RaidID), IDataReader)
        End Function
        Public Overrides Function tss_GetRaidsByPage(ByVal BoardID As Integer, _
                                                     ByVal PageNumber As Integer, _
                                                     ByVal PageSize As Integer, _
                                                     ByVal SortExpression As String, _
                                                     ByVal SortDirection As String, _
                                                     ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRaidsByPage", _
                                                                  BoardID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Function tss_GetRaidsForPlayerByPage(ByVal PlayerID As Integer, _
                                                              ByVal PageNumber As Integer, _
                                                              ByVal PageSize As Integer, _
                                                              ByVal SortExpression As String, _
                                                              ByVal SortDirection As String, _
                                                              ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRaidsForPlayerByPage", _
                                                                  PlayerID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteRaid(ByVal RaidID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteRaid", RaidID)
        End Sub
        Public Overrides Function tss_AddRaid(ByVal RaidValue As Double, _
                                              ByVal RaidDate As DateTime, _
                                              ByVal RaidAttendanceFlag As Boolean, _
                                              ByVal MobID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddRaid", _
                                                     RaidValue, _
                                                     RaidDate, _
                                                     RaidAttendanceFlag, _
                                                     MobID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateRaid(ByVal RaidID As Integer, _
                                            ByVal RaidValue As Double, _
                                            ByVal RaidDate As DateTime, _
                                            ByVal RaidAttendanceFlag As Boolean, _
                                            ByVal MobID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateRaid", _
                                          RaidID, _
                                          RaidValue, _
                                          RaidDate, _
                                          RaidAttendanceFlag, _
                                          MobID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "Roster Methods"
        Public Overrides Function tss_GetRoster(ByVal RosterID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRoster", RosterID), IDataReader)
        End Function
        Public Overrides Function tss_GetRostersByPage(ByVal RaidID As Integer, _
                                                       ByVal PageNumber As Integer, _
                                                       ByVal PageSize As Integer, _
                                                       ByVal SortExpression As String, _
                                                       ByVal SortDirection As String, _
                                                       ByRef RowsAffected As Integer) As IDataReader
            Dim reader As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetRostersByPage", _
                                                                  RaidID, _
                                                                  PageNumber, _
                                                                  PageSize, _
                                                                  SortExpression, _
                                                                  SortDirection)
            RowsAffected = reader.RecordsAffected
            Return CType(reader, IDataReader)
        End Function
        Public Overrides Sub tss_DeleteRoster(ByVal RosterID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_DeleteRoster", RosterID)
        End Sub
        Public Overrides Function tss_AddRoster(ByVal RaidID As Integer, _
                                                ByVal PlayerID As Integer) As Integer
            Try
                Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_AddRoster", _
                                                     RaidID, _
                                                     PlayerID), Integer)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Function
        Public Overrides Sub tss_UpdateRoster(ByVal RosterID As Integer, _
                                              ByVal RaidID As Integer, _
                                              ByVal PlayerID As Integer)
            Try
                SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_UpdateRoster", _
                                          RosterID, _
                                          RaidID, _
                                          PlayerID)
            Catch ex As SqlClient.SqlException
                Throw New ApplicationException(ex.ErrorCode.ToString() + ": " + ex.Message)
            End Try
        End Sub
#End Region

#Region "System Methods"
        Public Overrides Function tss_GetSystems() As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "tss_GetSystems"), IDataReader)
        End Function
#End Region

    End Class

End Namespace